package com.ytc.content.controller;

import com.ytc.commons.model.dto.BindTeachplanMediaDto;
import com.ytc.commons.model.dto.TeachplanDto;
import com.ytc.commons.model.vo.ResponseResult;
import com.ytc.commons.model.vo.TeachplanVo;
import com.ytc.commons.utils.BeanHelper;
import com.ytc.content.domain.Teachplan;
import org.springframework.web.bind.annotation.*;
import com.ytc.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程计划前端控制器
 * </p>
 */
@Slf4j
@RestController
@RequestMapping("/teachplan")
public class TeachplanController {

    @Autowired
    private TeachplanService teachplanService;


    /*
     * 根据课程id查询课程的章节
     * GET:/{courseId}/tree-nodes
     * */
    @GetMapping("/{courseId}/tree-nodes")
    public ResponseResult<TeachplanVo> treeNodes(@PathVariable("courseId") Long courseId) {
        return teachplanService.treeNodes(courseId);
    }

    /*
     * //保存或者更新课程章节
     * Post:
     * 参数：TeachplanDto
     * 响应ResponseResult
     * */
    @PostMapping
    public ResponseResult saveOrUpdateTeachplan(@RequestBody TeachplanDto dto) {
        teachplanService.saveOrUpdateTeachplan(dto);
        return ResponseResult.okResult();
    }

    //删除课程计划/*
    // DElETE  {id}
    //
    // 返回值NUll
    // */
    @DeleteMapping("/{id}")
    public ResponseResult deleteTeachplan(@PathVariable("id") Long id) {

        return teachplanService.deleteTeachplan(id);

    }

    /*
     * //课程计划绑定视频
     * POST /teachplan/media/association
     * 响应：BindTeachplanMediaDto
     * 返回：null
     * */
    @PostMapping("/media/association")
    public ResponseResult associationMedia(@RequestBody BindTeachplanMediaDto dto) {
        return teachplanService.associationMedia(dto);
    }

    /*
    //解除视频与课程计划之间的绑定
    *  DELETE /teachplan/media/{teachPlanMediaId}
    //返回：null
    * */
    @DeleteMapping("/media/{teachPlanMediaId}")
    public ResponseResult teachPlanMediaId(@PathVariable("teachPlanMediaId") Long teachPlanMediaId, Long courseBaseId) {

        return teachplanService.teachPlanMediaId(teachPlanMediaId, courseBaseId);
    }
    /*
    * 根据id查询课程计划
    * GET /{teachplanId}
    * Vo
    * */
    @GetMapping("/{teachplanId}")
    public ResponseResult<TeachplanVo> findById(@PathVariable("teachplanId") Long teachplanId){
        Teachplan teachplan = teachplanService.getById(teachplanId);
        TeachplanVo teachplanVo = BeanHelper.copyProperties(teachplan, TeachplanVo.class);
        return ResponseResult.okResult(teachplanVo);
    }


}
